import React from "react";
import {
  Form,
  Button,
  InputNumber,
  Input,
  TextArea,
  Uploader,
} from "@nutui/nutui-react-taro";
import {
  changePasswordApi,
  changeUserInfoApi,
} from "../../../../servers/servers";
import { BASE_URL } from "../../../../servers/http";
import Taro from "@tarojs/taro";

const info = () => {
  return (
    <>
      <Form
        labelPosition="right"
        footer={
          <>
            <Button formType="submit" block type="primary" size='xlarge'>
              提交
            </Button>
          </>
        }
        onFinish={async (values) => {
          const { avatar = [] } = values ?? {};
          try {
            let avatarUrl = "";

            if (avatar?.length > 0) {
              avatarUrl = avatar?.[0]?.responseText?.data
                ? JSON.parse(avatar?.[0]?.responseText?.data).data?.url
                : "";
            }

            await changeUserInfoApi({
              ...values,
              avatar: avatarUrl,
            });

            Taro.showToast({
              title: "修改成功",
              icon: "none",
              duration: 2000,
            });

            //  返回上一页
            // Taro.navigateBack();

            // 清空缓存
            // Taro.clearStorage();
          } catch (error) {}
        }}
      >
        <Form.Item
          label="头像"
          name="avatar"
          rules={[{ required: true, message: "请上传新头像" }]}
        >
          <Uploader
            url={`${BASE_URL}/common/image`}
            uploadLabel="新头像"
            style={{ marginInlineEnd: "10px" }}
          />
        </Form.Item>

        {/* <Form.Item
          required
          label="昵称"
          name="netname"
          rules={[{ required: true, message: "请输入新昵称" }]}
        >
          <Input
            className="nut-input-text"
            placeholder="请输入新昵称"
            type="text"
          />
        </Form.Item> */}
      </Form>
    </>
  );
};

export default info;
